package com.org.cys.service.impl.${package};

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.org.cys.dao.base.IGeneralDao;
import com.org.cys.pojo.base.Page;
import com.org.cys.service.${package}.${entityName}Service;
import com.org.cys.util.PageData;
import com.org.cys.util.IdWorker;


/**
 *	${entityComment} Service实现类
 *	@author caiyushen
 */
@Service("${entityNameSmall}ServiceImpl")
public class ${entityName}ServiceImpl implements ${entityName}Service {
  
  @Resource(name="generalDao")
  private IGeneralDao generalDao;
  
  public static String XMLMapper = "${entityName}Mapper";
  
  /**
	* 装载${entityName}
	* @param PageData
	* @return
	* @throws Exception 
	* */
  @Override
  public PageData getEntityById(PageData pd) throws Exception {
	  return (PageData) generalDao.findForObject(XMLMapper+".findById", pd);
  }
  
  /**
	* 保存${entityName}
	* @param PageData
	* @throws Exception
	* */
  @Override
  public void save(PageData pd) throws Exception{
  	  pd.put("id", IdWorker.getId());
  	  pd.put("createDate", new Date());
	  generalDao.save(XMLMapper+".save",pd);
  }
  
  /**
   * 批量保存${entityName}
   * @param PageData
   * @throws Exception
   * */
  public void saveBatch(List<PageData> pdList) throws Exception{
  	  for(PageData pd : pdList){
		  pd.put("id", IdWorker.getId());
	  }
	  generalDao.batchSave(XMLMapper+".saveBatch",pdList);
  }
  
  /**
	* 更新${entityName}
	* @param PageData
	* @throws Exception
	* */
  @Override
  public void update(PageData pd) throws Exception{
	  generalDao.update(XMLMapper+".update",pd);
  }
  
  /**
	* 删除${entityName}
	* @param PageData
	* @throws Exception
	* */
  @Override
  public void delete(PageData pd) throws Exception{
	  generalDao.delete(XMLMapper+".delete", pd);
  }
  
  /**
	* ${entityName}列表
	* @param PageData
	* @throws Exception
	* */
  @Override
  public List<PageData> dataList(Page page) throws Exception{
	  return (List<PageData>) generalDao.findForList(XMLMapper+".dataListPage", page);
  }
  
  /**
	* 获取所有${entityName}数据
	* @param PageData
	* @throws Exception
	* */
  @Override
  public List<PageData> listAll(PageData pd) throws Exception{
	  return (List<PageData>) generalDao.findForList(XMLMapper+".listAll", pd);
  }
  
  /**
	* 批量删除${entityName}
	* @param ArrayDATA_IDS[]
	* @throws Exception
	* */
  @Override
  public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
	  generalDao.delete(XMLMapper+".deleteAll", ArrayDATA_IDS);
  }
  
}